<extend name="public@base5"/>
<block name="head">
    <style>
        .data-item-tr, .search-btn {
            cursor: pointer;
        }

        .col-xs-3 {
            padding-right: 0;
        }
    </style>
</block>
<block name="main">
    <div class="wrap js-check-wrap">
        <notempty name="filters">
            <form method="get" action="{:url('Theme/dataSource')}" id="search-form">
                <div class="row">
                    <foreach name="filters" item="filter" key="filterName">
                        <switch name="filter.type">
                            <case value="text">
                                <div class="col-xs-3">
                                    <div class="form-group">
                                        <label class="sr-only">{$filter.title|default=''}</label>
                                        <input type="text" class="form-control" name="{$filterName}"
                                               placeholder="{$filter.placeholder|default=''}"
                                               value="{$form[$filterName]|default=''}">
                                    </div>
                                </div>
                            </case>
                            <case value="select">
                                <div class="col-xs-3">
                                    <div class="form-group">
                                        <label class="sr-only">{$filter.title|default=''}</label>
                                        <select class="form-control" name="{$filterName}">
                                            <notempty name="filter.placeholder">
                                                <option value="">{$filter.placeholder|default=''}</option>
                                            </notempty>
                                            <foreach name="filter.options" item="option">
                                                <php>
                                                    $option_selected='';
                                                    if(isset($form[$filterName]) && $form[$filterName]==$option['id']){
                                                    $option_selected='selected';
                                                    };
                                                </php>
                                                <option value="{$option.id}" {$option_selected}>{$option.name}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                            </case>
                        </switch>
                    </foreach>
                    <div class="col-xs-3">
                        <input type="hidden" value="{$data_source}" name="data_source">
                        <button type="submit" class="btn btn-primary">{:lang('Search')}</button>
                        <a class="btn btn-danger" href="{:url('Theme/dataSource')}?data_source={$data_source}">{:lang('Clear')}</a>
                    </div>
                </div>
                <!--<div class="form-group">-->
                <!--<div class="input-group">-->
                <!--<input type="text" class="form-control" name="keyword" value="{$keyword|default=''}"-->
                <!--placeholder="请输入关键字">-->
                <!--<input type="hidden" value="{$data_source}" name="data_source">-->
                <!--<span class="input-group-addon search-btn" onclick="submitSearchForm()">GO!</span>-->
                <!--</div>-->
                <!--</div>-->
            </form>
        </notempty>
        <form method="post" class="js-ajax-form">

            <table class="table table-hover table-bordered table-list">
                <thead>
                <tr>
                    <th width="16">
                        <if condition="$multi">
                            <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                        </if>
                    </th>
                    <th width="50">ID</th>
                    <th>{:lang('Name')}</th>
                </tr>
                </thead>
                <tbody>
                {$items_tree}
                </tbody>
            </table>
        </form>
    </div>
</block>
<block name="scripts">
    <script>
        $('.data-item-tr').click(function (e) {

            var $this = $(this);
            if ($(e.target).is('input')) {
                return;
            }

            var $input = $this.find('input');
            if ($input.is(':checked')) {
                $input.prop('checked', false);
            } else {
                $input.prop('checked', true);
            }


        });

        function submitSearchForm() {
            $('#search-form').get(0).submit();
        }

        function confirm() {
            var selectedObjectsId = [];
            var selectedObjectsName = [];
            var selectedObjects = [];
            $('.js-select-box:checked').each(function () {
                var $this = $(this);
                selectedObjectsId.push($this.val());
                selectedObjectsName.push($this.data('name'));

                selectedObjects.push({
                    id: $this.val(),
                    name: $this.data('name')
                });
            });

            return {
                selectedObjects: selectedObjects,
                selectedObjectsId: selectedObjectsId,
                selectedObjectsName: selectedObjectsName
            };
        }
    </script>
</block>
